<?php include "include/header.php" ?>
<div class="main-content">
					<div class="container">

						<div class="page-content">
						
							<!-- Heading -->
							<div class="single-head">
								<!-- Heading -->
								<h3 class="pull-left"><i class="fa fa-tags green"></i> Report</h3>
								<!-- Bread crumbs -->
								<div class="breads pull-right">
									<strong>Nav</strong> : <a href="<?=base_url('/')?>">Home</a> / <a href="<?=base_url('report/reports')?>">Report</a>
								</div>
								<div class="clearfix"></div>
							</div>
							
							<!-- Posts page -->
							<div class="page-posts">
								<!-- Nav tabs -->
								<div class="page-tabs">
									<ul class="nav nav-tabs">
										<li class="active"><a href="#posts" class="br-lblue" data-toggle="tab"><i class="fa fa-tags lblue"></i> Report</a></li>
										<li><a href="#postnew" class="br-red" data-toggle="tab"><i class="fa fa-tag red"></i> Add Report</a></li>
									</ul>
									<!-- Tab panes -->
									<span style="float:right;font-size:20px;"><a class="btn btn-xs" data-toggle="modal" href="#email_table"><i class="fa fa-envelope" style="font-size:18px;"></i></a></span>
									<div class="tab-content">
										<div class="tab-pane fade active in" id="posts">
											<div class="table-responsive email_body">
												<form id="report_form">
													<table class="table table-bordered">
														<thead>
															<tr>
																<th><input type="checkbox" name="tablechoice" onclick="var ck = this.checked;$(':checkbox').each(function(){this.checked = ck});"/></th>
																<th>Report name</th>
																<th>Report email</th>
																<th>Edits</th>
															</tr>
														</thead>
														<tbody>														
															<?php foreach ( $all_report as $row ) { ?>
																<tr>
																	<td class="ri"><input type="checkbox" name="report_id" value="<?=$row['report_id']?>" /></td>
																	<td class="rn"><?=$row['report_name']?></td>
																	<td class="re"><?=$row['report_email']?></td>
																	<td>
																		<a data-toggle="modal" href="#report_update" class="btn btn-xs btn-danger report_edit"><i class="fa fa-pencil"></i></a>																
																		<a class="btn btn-xs btn-success report_del" onclick="confirm('Are you sure to delete?',function(flag){if(flag){location.href='<?=base_url('report/delete')?>?report_id=<?=$row['report_id']?>'}})" href="javascript:;"><i class="fa fa-trash-o"></i> </a>
																	</td>
																</tr>
															<?php } ?>
														</tbody>
													</table>
												</form>
											</div><!-- Table responsive end -->
											<!--
											<ul class="pagination pull-right">
												<li><a href="#">&laquo;</a></li>
												<li><a href="#">1</a></li>
												<li><a href="#">2</a></li>
												<li><a href="#">3</a></li>
												<li><a href="#">4</a></li>
												<li><a href="#">5</a></li>
												<li><a href="#">&raquo;</a></li>
											</ul>-->
											<div class="clearfix"></div>
										</div>
										<div class="tab-pane fade" id="postnew">
											<!-- Heading -->
											<h4>Add Report</h4>	
											<form class="form-horizontal" role="form" method="post" action="<?=base_url('report/add')?>">
												<!-- Post title area -->
												<div class="form-group">
													<label for="title" class="col-md-2 control-label">Report Name</label>
													<div class="col-md-10">
														<input type="text" name="report_name" class="form-control" id="title" placeholder="Enter Report Name">
													</div>
												</div>
												<!-- Post tag area -->
												<div class="form-group">
													<label for="tag" class="col-md-2 control-label">Report Email</label>
													<div class="col-md-10">
														<input type="text" name="report_email" class="form-control" id="title" placeholder="Enter Email">
													</div>
												</div>
												
												<!-- Button -->
												<div class="form-group">
													<div class="col-md-offset-2 col-md-10">
													<div class="pull-right">
														<!-- Buttons -->
														<input type="submit" class="btn btn-default" value="Add" />
													</div>
													<div class="clearfix"></div>
												</div>
											</form>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div> <!-- Posts page end -->
							<!-- report update form -->
							<div class="modal fade" id="report_update" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
								<div class="modal-dialog">
								    <div class="modal-content">    
					 			        <div class="modal-header">
									        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
										        <h4 class="modal-title" id="exampleModalLabel">Update Report</h4>
										</div>
									    <div class="modal-body">
										    <form class="form-horizontal" role="form" method="post" action="<?=base_url('report/update')?>">
										    	<input type="checkbox" name="report_id" id="reportId" checked="checked" hidden>
										        <div class="form-group">
													<label for="title" class="col-lg-2 control-label">Report Name</label>
													<div class="col-lg-10">
														<input type="text" name="report_name" class="form-control" id="title" >
													</div>
												</div>
												<!-- Post tag area -->
												<div class="form-group">
													<label for="email" class="col-lg-2 control-label">Report Email</label>
													<div class="col-lg-10">
														<input type="text" name="report_email" class="form-control" id="email">
													</div>
												</div>
												<button type="submit" class="btn btn-info btn-block">Update</button>
										    </form>
										</div>
										<div class="clearfix"></div>
										<div class="modal-footer">
										    
									    </div>
								    </div>
						        </div>
							</div>
							<!-- report update form -->
							<!-- email modal form -->
							<div class="modal fade" id="email_table" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
								<div class="modal-dialog">
								    <div class="modal-content">    
					 			        <div class="modal-header">
									        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
										        <h4 class="modal-title" id="exampleModalLabel">Email This Table</h4>
										</div>
									    <div class="modal-body">
										    <form id="sendmailForm1" class="form-horizontal" role="form">
												<div class="form-group" id="email_form_group">
													<label for="email" class="col-lg-2 control-label">Email</label>
													<div class="col-lg-10">
														<input type="text" name="email" class="form-control" id="email1" placeholder="Email address">
													</div>
												</div>
												<div class="form-group">
													<label for="subject" class="col-sm-2 control-label">Subject</label>
													<div class="col-sm-10">
														<input type="text" name="subject" class="form-control" id="subject" placeholder="Email title" />
													</div>
												</div>
												<div class="form-group hidden">
													<label for="message" class="col-sm-2 control-label">Message</label>
													<div class="col-sm-10">
														<textarea id="email_content" class="" name="content" class="form-control" placeholder="Type your message ..." style="width: 100%; height: 200px"></textarea>
													</div>
												</div>
												<button type="submit" class="btn btn-info btn-block">Send mail</button>
										    </form>
										</div>
										<div class="clearfix"></div>
										<div class="modal-footer"></div>
								    </div>
						        </div>
							</div>
							<!-- email modal form -->
						</div>
						
					</div>
				</div>
				</div>
			<!-- Mainbar ends -->
			
			<div class="clearfix"></div>
		</div>
<?php include "include/js.php" ?>
<!-- script for this page -->
<script>
$(document).ready(function(){
	
	$("#report_update").on('show.bs.modal', function (event) {
		var button = $(event.relatedTarget);
		var report_id = button.parent().prevAll(".ri").children().val();
		var report_name = button.parent().prevAll(".rn").text();
		var report_email = button.parent().prevAll(".re").text();
		var modal = $(this);
		modal.find('#reportId').val(report_id);
  		modal.find('#title').val(report_name);
  		modal.find('#email').val(report_email);
	});	
	$("#email_table").on('show.bs.modal', function (event) {
		var header = "<head><meta chaset='utf-8'><title>Report Data</title><style>table{font-family: verdana,arial,sans-serif;font-size:11px;color:#333333;border-width: 1px;border-color: #a9c6c9;border-collapse: collapse;}table caption{font-size:16px;line-height:28px;text-align:left;font-weight:bold;}table th {border-width: 1px;padding: 8px;border-style: solid;border-color: #a9c6c9;background-color: #c3dde0;}table td:first-child{background-color: #d4e3e5;}table td {border-width: 1px;padding: 8px;border-style: solid;border-color: #a9c6c9;background-color: #ffffff;}</style></head><body>";
		var footer = "</body></html>";
		var content = $(".email_body").html();
		var email_content = header+content+footer;
		var modal = $(this);
		modal.find('#email_content').val(email_content);
	});
	$('#sendmailForm1').ajaxForm({
        beforeSubmit:function(){if ($('#email1').val() == '' || !$('#email1').val().match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) {
                       $('#email_form_group').addClass('has-error');return false;}
                     },
        type: 'post',
        url: "<?=base_url('mail/send_mail')?>",
        dataType: 'json',
        resetForm: true,
        success: function(){
        	$('#email_table').modal('hide');
        }
    });
});           
</script>
<?php include "include/footer.php" ?>